import {
    get,
    post
} from '../../http/axios'

export default {
    // 命名空间
    namespaced: true,
    // 状态 -> data
    state: {
        userList: [],
        privilegeList: {},
        priAll: []


    },
    // 突变 -> 改变state中变量值的唯一方式
    mutations: {
        set_userList(state, val) {
            state.userList = val;
        },
        set_privilegeList(state, val) {
            state.privilegeList = val;

        },
        set_priAll(state, val) {
            state.priAll = val;
        },

    },
    // 动作 -> methods，发送请求
    actions: {
        async findAll_user({
            commit
        }) {
            let res = await get('/baseUser/findAll');
            // 调用突变中的方法
            commit('set_userList', res.data);
        },
        async saveU({
            commit
        }, params) {
            let res = await post('/baseUser/saveOrUpdate', params);

            // 调用突变中的方法
            // commit('set_userList', res.data);
        },
        async deleteById({
            commit
        }, params) {
            let res = await get('/baseUser/deleteById', params);
            return res;
        },
        async page_query(context, params) {
            let res = await get('/baseUser/pageQuery', params);
            context.commit('set_userList', res.data.list);

        },
        async privilege_query(context, params) {
            let res = await get('/privilege/findByParentId', params);
            context.commit('set_privilegeList', res.data[0].name);


        },
        async privilege_findAll(context) {
            let res = await get('/privilege/findPrivilegeTree');
            context.commit('set_priAll', res.data);

        }


    }
}